﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Order.aspx.cs" Inherits="CustomerMgr.Web.Order" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Vista" />
    <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="all"
        ControlsToSkip="Scrollbars" Skin="Windows7"></telerik:RadFormDecorator>
    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">
        <script type="text/javascript">
            var popUp;
            function PopUpShowing(sender, eventArgs) {
                popUp = eventArgs.get_popUp();
                var gridWidth = sender.get_element().offsetWidth;
                var gridHeight = sender.get_element().offsetHeight;
                var popUpWidth = popUp.style.width.substr(0, popUp.style.width.indexOf("px"));
                var popUpHeight = popUp.style.height.substr(0, popUp.style.height.indexOf("px"));
                popUp.style.left = ((gridWidth - popUpWidth) / 2 + sender.get_element().offsetLeft).toString() + "px";
                popUp.style.top = ((gridHeight - popUpHeight) / 2 + sender.get_element().offsetTop).toString() + "px";
            } 
        </script>
    </telerik:RadScriptBlock>
    <fieldset>
        <legend>Thông tin khách hàng</legend>
        <table cellpadding="2" cellspacing="2" width="100%">
            <tr>
                <td>
                    Ngày mua hàng
                </td>
                <td colspan="2">
                    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" ShowPopupOnFocus="true"
                        DatePopupButton-Visible="true" />
                </td>
            </tr>
            <tr>
                <td>
                    Chọn KH
                </td>
                <td colspan="2">
                    <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="390px" Height="140px"
                        AllowCustomText="true" MarkFirstMatch="true" EmptyMessage="Nhập tên khách hàng"
                        Skin="Vista" DataTextField="Name" DataValueField="Id" OnItemDataBound="RadComboBox1_ItemDataBound">
                    </telerik:RadComboBox>
                </td>
            </tr>
            <tr>
                <td>
                    Thêm KH mới
                </td>
                <td width="420px">
                    <asp:TextBox ID="txtAddCusName" runat="server" Width="390px" />
                </td>
                <td style="text-align: left;">
                    <asp:Button ID="btnAddCustomer" runat="server" Text="Thêm mới KH" OnClick="btnAddCustomer_Click" />
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>Thông tin sản phẩm</legend>
        <div>
            <asp:HiddenField ID="hdfOrderId" runat="server" Value="0" />
            <asp:HiddenField ID="hdfCustomerId" runat="server" Value="0" />
            <telerik:RadGrid ID="RadGrid1" runat="server" CssClass="RadGrid" GridLines="None"
                AllowPaging="True" PageSize="20" AllowSorting="True" AutoGenerateColumns="False"
                ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticInserts="false"
                OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand"
                OnDeleteCommand="RadGrid1_DeleteCommand" AllowAutomaticUpdates="false" HorizontalAlign="NotSet"
                OnNeedDataSource="RadGrid1_NeedDataSource" Skin="Windows7">
                <MasterTableView CommandItemDisplay="Top" DataKeyNames="Id" EditMode="PopUp">
                    <Columns>
                        <telerik:GridTemplateColumn HeaderText="STT">
                            <HeaderStyle HorizontalAlign="Center" Width="40px" />
                            <ItemTemplate>
                                <asp:Label ID="lblOrder" runat="server" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn UniqueName="ProductName" HeaderText="Tên SP" DataField="ProductName">
                            <HeaderStyle Width="260px"></HeaderStyle>
                        </telerik:GridBoundColumn>
                        <telerik:GridNumericColumn DataField="Quantity" HeaderText="Số lượng" UniqueName="Quantity">
                        </telerik:GridNumericColumn>
                        <telerik:GridNumericColumn DataField="Price" HeaderText="Unit Price" UniqueName="Price">
                        </telerik:GridNumericColumn>
                        <telerik:GridEditCommandColumn EditText="Sửa">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn CommandName="Delete" Text="Xóa" UniqueName="column">
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings InsertCaption="Thêm đơn hàng chi tiết" CaptionFormatString="Cập nhật sản phẩm trong đơn hàng: {0}"
                        CaptionDataField="PruductName" EditFormType="Template">
                        <FormTemplate>
                            <table id="Table1" cellspacing="1" cellpadding="1" width="350" border="0">
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Tên sản phẩm: <font color="red">(*)</font>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtProductName" Text='<%# Bind( "ProductName") %>' runat="server" Width="99%">
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Số lượng: <font color="red">(*)</font>
                                    </td>
                                    <td>
                                        <telerik:RadNumericTextBox ShowSpinButtons="True" DbValue='<%# Bind("Quantity") %>'
                                            Type="Number" ID="txtQuantity" runat="server"
                                            Width="101px" Value="1">
                                            <NumberFormat AllowRounding="True" KeepNotRoundedValue="False" />
                                        </telerik:RadNumericTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Giá SP: <font color="red">(*)</font>
                                    </td>
                                    <td>
                                        <span>
                                            <telerik:RadNumericTextBox runat="server" ID="tbUnitPrice" Width="80px" DbValue='<%# Bind("Price") %>'>
                                            </telerik:RadNumericTextBox><span style="color: Red"><asp:RequiredFieldValidator
                                                ID="RequiredFieldValidator1" ControlToValidate="tbUnitPrice" ErrorMessage="*"
                                                runat="server">
                                            </asp:RequiredFieldValidator></span>
                                    </td>
                                </tr>
                            </table>
                            <table style="width: 100%">
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Thêm mới" : "Cập nhật" %>'
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                        </asp:Button>&nbsp;
                                        <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                                        </asp:Button>
                                    </td>
                                </tr>
                            </table>
                        </FormTemplate>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnPopUpShowing="PopUpShowing" />
                </ClientSettings>
            </telerik:RadGrid>
        </div>
        <div style="text-align: right; margin-top: 10px;">
            <asp:Button ID="btnSave" runat="server" Text="Ghi lại" />
            <asp:Button ID="btnPrintAndSave" runat="server" Text="Ghi lại & in phiếu" />
            <asp:Button ID="btnCancel" runat="server" Text="Ghi lại" />
        </div>
    </fieldset>
</asp:Content>
